public class MyException {
    public static void main(String[] args) {
        Person p1 = new Person("ych", 26);
        try {
            p1.setAge(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws Exception {
        if (age > 0 && age < 100) {
            this.age = age;
        } else {
            throw new AgeException("年龄必须大于0小于100");
        }
    }
}
class AgeException extends Exception {
    public AgeException(String message) {
        super(message);
    }
}
